﻿@page "/user/UpdatePwd"
@inherits DataComponentBase<UserPwd>
<div style="width:70%">
    <Form @ref="_meunForm" Model="@DataSource" OnFinish="FormSubmit">
        <FormItem Label="初始密码">
            <InputPassword Placeholder="请输入初始密码" @bind-Value="@context.OriginalPwd" />
        </FormItem>
        <FormItem Label="新密码">
            <InputPassword Placeholder="请输入新密码" @bind-Value="@context.NewPwd" />
        </FormItem>
        <FormItem Label="确认密码">
            <InputPassword Placeholder="请确认密码" @bind-Value="@context.SurePwd"  />
        </FormItem>
    </Form>
</div>

@code{
    UserPwd DataCatch;
    public override async Task<bool> Validate()
    {
        if (DataSource.NewPwd != DataSource.SurePwd)
        {
            Message.Warn("两次密码不一致，请重新输入");
            return false;
        }
        DataSource.AToB(out DataCatch);
        DataSource.OriginalPwd = CommonlyHelper.SHA256EncryptString(DataSource.OriginalPwd);
        DataSource.SurePwd = CommonlyHelper.SHA256EncryptString(DataSource.SurePwd);
        DataSource.NewPwd = CommonlyHelper.SHA256EncryptString(DataSource.NewPwd);
        return await base.Validate();
    }
    public override async Task<bool> FormSubmit()
    {
        var result = await base.FormSubmit();
        if (!result)
        {
            DataSource = DataCatch;
            StateHasChanged();
        }
        return result;
    }
}